Package gwtappcontainer.server.apps.geolocation

Source Code of gwtappcontainer.server.apps.geolocation.GeoLocationAPITest

package gwtappcontainer.server.apps.geolocation;

import static org.junit.Assert.assertTrue;
import gwtappcontainer.server.apps.content.ContentAPI;
import gwtappcontainer.server.apps.geolocation.GeoLocationAPI;
import gwtappcontainer.shared.apis.APIResponse;
import gwtappcontainer.shared.apis.APIResponse.Status;
import gwtappcontainer.testhelpers.APITestHelper;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

public class GeoLocationAPITest {
 
private final APITestHelper helper = new APITestHelper();
 
  @Before
  public void setUp() {
    helper.setUp();
  }
 
  @After
  public void tearDown() {
    helper.tearDown();
  }
 
  @Test
  public void canGetCityContent() {
    ContentAPI contentAPI = new ContentAPI();
   
    contentAPI.addNewTag("ishakriyaschedule_mumbai", helper.loginAsDeveloper());
    contentAPI.setContent("content for mumbai", "ishakriyaschedule_mumbai", true, helper.loginAsPortalAdmin());
   
    GeoLocationAPI geoApi = new GeoLocationAPI();
    String content = geoApi.getContentForCity("ishakriyaschedule", "mumbai").object.toString();
    assertTrue(content.equals("content for mumbai"));               
  }
 
  @Test
  public void cityAndTagAreCaseInsensitive() {
    ContentAPI contentAPI = new ContentAPI();
   
    contentAPI.addNewTag("ishakriyaschedule_mumbai", helper.loginAsDeveloper());
    contentAPI.setContent("content for mumbai", "ishakriyaschedule_mumbai", true, helper.loginAsPortalAdmin());
   
    GeoLocationAPI geoApi = new GeoLocationAPI();
    String content = geoApi.getContentForCity("ishakriyASchedule", "mUMBAi").object.toString();
    assertTrue(content.equals("content for mumbai"));
  }
 
  @Test
  public void canGetDefaultContentIfCityContentNotAvailable() {
    ContentAPI contentAPI = new ContentAPI();
   
    contentAPI.addNewTag("ishakriyaschedule_default", helper.loginAsDeveloper());
    contentAPI.setContent("content for default", "ishakriyaschedule_default", true, helper.loginAsPortalAdmin());
   
    GeoLocationAPI geoApi = new GeoLocationAPI();
    String content = geoApi.getContentForCity("ishakriyASchedule", "mUMBAi").object.toString();
    assertTrue(content.equals("content for default"));
  }
 
  @Test
  public void resoureNotFoundErrorIfBothDefaultContentAndCityContentNotAvailable() {
    GeoLocationAPI geoApi = new GeoLocationAPI();
   
    APIResponse response = geoApi.getContentForCity("ishakriyaschedule", "mumbai");
    assertTrue(response.statusCode == Status.ERROR_RESOURCE_DOES_NOT_EXIST)
  }
 
  @Test
  public void canGetDefaultContentIfCityContentNotPublished() {
    ContentAPI contentAPI = new ContentAPI();
   
    //add content for mumbai but don't publish it
    contentAPI.addNewTag("ishakriyaschedule_mumbai", helper.loginAsDeveloper());
    contentAPI.setContent("content for mumbai", "ishakriyaschedule_mumbai",
        false, helper.loginAsPortalAdmin());
   
    //add content for default
    contentAPI.addNewTag("ishakriyaschedule_default", helper.loginAsDeveloper());
    contentAPI.setContent("content for default", "ishakriyaschedule_default",
        true, helper.loginAsPortalAdmin());
   
    GeoLocationAPI api = new GeoLocationAPI();
    String content = api.getContentForCity("ishakriyaSchedule", "mumbai").object.toString();
    assertTrue(content.equals("content for default"));   
  }
 
  @Test
  public void canGetMostReleventContent() {
    ContentAPI contentAPI = new ContentAPI();
   
    //add tags
    contentAPI.addNewTag("testtag_melbourne", helper.loginAsDeveloper());
    contentAPI.addNewTag("testtag_vic", helper.loginAsDeveloper());
    contentAPI.addNewTag("testtag_australia", helper.loginAsDeveloper());
    contentAPI.addNewTag("testtag_default", helper.loginAsDeveloper());
   
    //add content for city
    contentAPI.setContent("content for melbourne", "testtag_melbourne",
        true, helper.loginAsPortalAdmin());
   
    //add content for region
    contentAPI.setContent("content for victoria", "testtag_vic",
        true, helper.loginAsPortalAdmin());
   
    //add content for country
    contentAPI.setContent("content for australia", "testtag_australia",
        true, helper.loginAsPortalAdmin());
   
    //add default content
    contentAPI.setContent("content for default", "testtag_default",
        true, helper.loginAsPortalAdmin());
       
    //city content if available
    GeoLocationAPI geoLocationAPI = new GeoLocationAPI();
    APIResponse response = geoLocationAPI.
        getMostRelevantContent("testtag", "melbourne",
            "vic", "australia");   
    String content = (String) response.object;
    assertTrue(content.equals("content for melbourne"));
    assertTrue(response.userFriendlyMessage.contains("testtag_melbourne"));
   
    //region content if city content is not available
    response = geoLocationAPI.
        getMostRelevantContent("testtag", "portland",
            "vic", "australia");
    content = (String) response.object;
    assertTrue(content.equals("content for victoria"));
    assertTrue(response.userFriendlyMessage.contains("testtag_vic"));
   
    //country content if both city and region not available
    response = geoLocationAPI.
        getMostRelevantContent("testtag", "sydney",
            "new south wales", "australia");
    content = (String) response.object;
    assertTrue(content.equals("content for australia"));
    assertTrue(response.userFriendlyMessage.contains("testtag_australia"));
   
    //default content if city, region and country contents not available
    response = contentAPI.setPublishStatus("testtag_australia", false, helper.loginAsPortalAdmin());
    assertTrue(response.statusCode == Status.SUCCESS);
   
    response = geoLocationAPI.
        getMostRelevantContent("testtag", "sydney",
            "new south wales", "australia");
    content = (String) response.object;
    assertTrue(content.equals("content for default"));
    assertTrue(response.userFriendlyMessage.contains("testtag_default"));     
 
}
TOP

Related Classes of gwtappcontainer.server.apps.geolocation.GeoLocationAPITest

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.